﻿namespace net.zxteam.ZXLexer.Dynamic.Internal
{
    using net.zxteam.ZXLexer.Tokens;
    using System;
    using System.Collections;
    using System.Collections.Generic;

    internal struct CharToken : ICharToken
    {
        private char _value;

        public CharToken(char value)
        {
            _value = value;
        }

        public char Value { get { return _value; } }

        public override string ToString()
        {
            return Value.ToString();
        }

        public IEnumerator<IToken> GetEnumerator()
        {
            throw new System.NotImplementedException();
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
            return this.GetEnumerator();
        }

        private struct Enumerator : IEnumerator<IToken> 
        {
            public CharToken Value;
            private bool End;

            public IToken Current
            {
                get
                {
                    if (!End) throw new InvalidOperationException();

                    return Value;
                }
            }

            public void Dispose() { }

            object IEnumerator.Current { get { return this.Current; } }

            public bool MoveNext()
            {
                if (End) return false; 
                
                return End = true;
            }

            public void Reset() { End = false; }
        }
    }
}
